package cvsexercise4;

public class ConditionalOperator {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		/* Write out a start message to the console */
		System.out.println("Exercise 4 - Conditional Operator started");
		
		/* Create and initialize the two String variables from Exercise 7 */
		String str1 = new String("HelloWorld");
		String str2 = new String("HelloJavaWorld");
		
		/* Output the String variables */
		System.out.println("String str1 = " + str1);
		System.out.println("String str2 = " + str2);
		
		/* Output the length of each string 
		 * NOTE: use the String class length() method 
		 */
		System.out.println("Length of str1 = " + str1.length());
		System.out.println("Length of str2 = " + str2.length());
		
		/* Output the fifth character of each string
		 * NOTE: use the  String class charAt() method  
		 */
		char str1CharVal = ' ';
		char str2CharVal = ' ';
		str1CharVal = str1.charAt(5);
		System.out.println("Character at index 5 of str1 = " + str1CharVal);
		str2CharVal = str2.charAt(5);
		System.out.println("Character at index 5 of str2 = " + str2CharVal);
		
		/* Local variables for use with conditional operator */
		String strResult = "";
		boolean bResult = false; 

		/* Test if the two characters are the same and write out a result message
		 * NOTE: Use the conditional operator instead of double selection!
		 */
		bResult = (str1CharVal == str2CharVal); 
		strResult = bResult ? "Both characters are the same!" : "Both characters are different!";
		System.out.println(strResult);
		
		/* Determine which string contains the word Java and write out a result message
		 * NOTE: Use the conditional operator instead of double selection!
		 */
		bResult = str1.contains("Java");
		strResult = bResult ? "str1 contains the word Java!" : "str2 contains the word Java!";
		System.out.println(strResult);

		/* Write out a completed message to the console */
		System.out.println("Exercise 4 - Conditional Operator completed");
	}
}
